from django.http import HttpResponse
from django.shortcuts import render_to_response
from django.template import RequestContext
from mhlandscaping.apps.contact.forms import ContactForm
from mhlandscaping.apps.contact.models import Entry

def contact(request):
    
    if request.method == 'POST':
        form = ContactForm(request.POST)
        
        if form.is_valid():
            entry = Entry()
            entry.first_name = form.cleaned_data['first_name']
            entry.last_name = form.cleaned_data['last_name']
            entry.email = form.cleaned_data['email']
            entry.enquiry = form.cleaned_data['enquiry']
            
            if form.cleaned_data['phone_number']:
                entry.phone_number = form.cleaned_data['phone_number']
                
            entry.save()
    else:
        form = ContactForm()
    

    return render_to_response('contact/templates/contact.html', 
                              {'form': form}, 
                              context_instance=RequestContext(request))

def newsletter(request):
    return render_to_response('contact/templates/newsletter.html', 
                              {}, 
                              context_instance=RequestContext(request))
